package com.hxw.openslplayer;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import java.util.List;

public class TestActivity {

    /**
     * 获取已安装的APP列表
     * @param ct
     * @return
     */
    public static List<PackageInfo> getInstallAppList(Context ct){
        PackageManager packageManager = ct.getPackageManager();
        return packageManager.getInstalledPackages(PackageManager.GET_CONFIGURATIONS);
    }

    /**
     * 获取指定APP的信息
     * @param ct
     * @param packageName
     * @return
     */
    public static PackageInfo getAPPInfo(Context ct,String packageName){
        PackageManager packageManager = ct.getPackageManager();
        try {
            return packageManager.getPackageInfo(
                    packageName, 0);
        } catch (PackageManager.NameNotFoundException e) {
            e.printStackTrace();
        }

        return null;
    }

    public void readPackageInfo(Context ct,PackageManager pm,PackageInfo info){
        if (ct ==null||info == null){
            return;
        }

        CharSequence label = pm.getApplicationLabel(info.applicationInfo);
        if (label != null){
            System.out.println("label："+ label);
        }

        int uid = info.applicationInfo.uid;
        System.out.println("UID:"+uid);//获取应用的UID

        String versionName = info.versionName;//版本名
        System.out.println("Version Name:"+versionName);

        int versionCode = info.versionCode;//版本号
        System.out.println("versionCode:"+versionCode);

        String packageName = info.packageName;//包名
        System.out.println("packageName:"+packageName);

        Drawable d = pm.getApplicationIcon(info.applicationInfo);
        Bitmap bm = ((BitmapDrawable) d).getBitmap();//图标
    }
}
